import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Params} from "@angular/router";
import {Observable} from "rxjs";

import {HomepageService} from "@homepage/homepage.service";
import {ToolsService} from "@shared/service/tools/tools.service";
import {ToolbarService} from "@shared/components/toolbar/toolbar.service";
import {FeedRespVO} from "@interface/index";



@Component({
  selector: 'seed-my-feed',
  templateUrl: './my-feed.component.html',
  styleUrls: ['./my-feed.component.scss']
})
export class MyFeedComponent implements OnInit {
  private userId;
  public scrollContainer: any;
  public feeds: Observable<FeedRespVO[]>;

  constructor(
    public homepageService: HomepageService,
    public toolsService: ToolsService,
    private _activatedRoute: ActivatedRoute,
    public toolBarService: ToolbarService
  ) {
    this.feeds = this.homepageService.feeds;
  }

  downloadAppTip() {
    this.toolsService.presentConfirm('下载求苗APP，看更多精彩内容！');
  }

  ngOnInit() {
    this._activatedRoute.queryParams.do(() => this.toolBarService.unfoldNav())
      .subscribe((params: Params) => {
        this.userId = params['userId'];
        if (params['userId']) {
          this.homepageService.getUserFeed(this.userId, 1, 10);
        }
      });
    this.scrollContainer = document.querySelector('#seed-scroll-content');
  }

}
